#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 110;
int dp[N];
int re_dp[N];
int num[N];
int n;


int main()
{
    cin >> n;
    for (int i = 1; i <= n; i ++ )
        cin >> num[i];

    for (int i = 1; i <= n; i ++ )
    {
        dp[i] = 1;
        for (int j = 1; j < i; j ++ )
            if (num[i] > num[j])
                dp[i] = max(dp[i], dp[j] + 1);
    }

    for (int i = n; i >= 0; i -- )
    {
        re_dp[i] = 1;
        for (int j = n; j > i; j -- )
            if (num[i] > num[j])
                re_dp[i] = max(re_dp[i], re_dp[j] + 1);
    }

    int res = 0;
    for (int i = 1; i <= n; i ++ )
        res = max(res, dp[i] + re_dp[i] - 1);
    cout << n - res << endl;
    return 0;
}